package com.leostadyn.stackfarm.timestatistics.presenter.admin;

import com.leostadyn.stackfarm.timestatistics.model.bean.DetailProjectBean;
import com.leostadyn.stackfarm.timestatistics.model.bean.EmployeeBean;
import com.leostadyn.stackfarm.timestatistics.model.bean.StaffTimeRecordBean;
import com.leostadyn.stackfarm.timestatistics.model.mentity.admin.FetchListModel;
import com.leostadyn.stackfarm.timestatistics.model.minterface.admin.IFetchListModel;
import com.leostadyn.stackfarm.timestatistics.presenter.BasePresenter;
import com.leostadyn.stackfarm.timestatistics.view.vinterface.admin.IFetchListView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import io.reactivex.disposables.CompositeDisposable;

public class FetchListPresenter extends BasePresenter<IFetchListView> {
    public void refresh(String end, String start, CompositeDisposable compositeDisposable) {
        if (!isViewAttached()) {
            return;
        }
        mView = getView();
        mView.showWaiting();

        FetchListModel.refresh(end, start, compositeDisposable, new IFetchListModel() {
            @Override
            public void onSuccess(ArrayList<DetailProjectBean> projectList, ArrayList<EmployeeBean> employeeList) {
                mView.successMessage(projectList, employeeList);
            }

            @Override
            public void onFailure(String string) {
                mView.failureMessage(string);
            }

            @Override
            public void onSuccessTimeRecord(StaffTimeRecordBean staffTimeRecordBean) {

            }

            @Override
            public void onCompleted() {
                mView.dismissWaiting();
            }

            @Override
            public void onFailure() {
            }

            @Override
            public void onSuccess() {
            }

            @Override
            public void noInternet() {
            }

            @Override
            public void onSuccessEmployee(ArrayList<EmployeeBean> employeeList) {
            }

            @Override
            public void onSuccessProject(ArrayList<DetailProjectBean> projectList) {
            }
        });
    }

    public void toProject(Date end, Date start, String uid, CompositeDisposable compositeDisposable) {
        if (!isViewAttached()) {
            return;
        }
        mView = getView();
        mView.showWaiting();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String startString = formatter.format(start);
        String endString = formatter.format(end);

        FetchListModel.toProject(endString, startString, uid, compositeDisposable, new IFetchListModel() {

            @Override
            public void onSuccessProject(ArrayList<DetailProjectBean> projectList) {
                mView.successProjectMessage(projectList);
            }

            @Override
            public void onCompleted() {
                mView.dismissWaiting();
            }

            @Override
            public void onFailure() {
            }

            @Override
            public void onSuccess() {
            }

            @Override
            public void noInternet() {
            }

            @Override
            public void onSuccessEmployee(ArrayList<EmployeeBean> employeeList) {
            }

            @Override
            public void onSuccess(ArrayList<DetailProjectBean> projectList, ArrayList<EmployeeBean> employeeList) {
            }

            @Override
            public void onFailure(String string) {
                mView.failureMessage(string);
            }

            @Override
            public void onSuccessTimeRecord(StaffTimeRecordBean staffTimeRecordBean) {

            }
        });
    }

    public void toPersonnel(Date end, Date start, String projectId, CompositeDisposable compositeDisposable) {
        if (!isViewAttached()) {
            return;
        }
        mView = getView();
        mView.showWaiting();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd");
        String startString = formatter.format(start);
        String endString = formatter.format(end);


        FetchListModel.toPersonnel(endString, startString, projectId, compositeDisposable, new IFetchListModel() {
            @Override
            public void onSuccessEmployee(ArrayList<EmployeeBean> employeeList) {
                mView.successEmployeeMessage(employeeList);
            }

            @Override
            public void onSuccess(ArrayList<DetailProjectBean> projectList, ArrayList<EmployeeBean> employeeList) {
            }

            @Override
            public void onFailure(String string) {
                mView.failureMessage(string);
            }

            @Override
            public void onSuccessTimeRecord(StaffTimeRecordBean staffTimeRecordBean) {

            }

            @Override
            public void onCompleted() {
                mView.dismissWaiting();
            }

            @Override
            public void onFailure() {
            }

            @Override
            public void onSuccess() {
            }

            @Override
            public void noInternet() {
            }

            @Override
            public void onSuccessProject(ArrayList<DetailProjectBean> projectList) {
            }

        });
    }

    public void toTimeRecord(HashMap<String, String> map, CompositeDisposable compositeDisposable) {
        if (!isViewAttached()) {
            return;
        }
        mView = getView();
        mView.showWaiting();
        FetchListModel.toTimeRecord(map,compositeDisposable, new IFetchListModel() {
            @Override
            public void onSuccessEmployee(ArrayList<EmployeeBean> employeeList) {

            }

            @Override
            public void onSuccessProject(ArrayList<DetailProjectBean> projectList) {

            }

            @Override
            public void onSuccess(ArrayList<DetailProjectBean> projectList, ArrayList<EmployeeBean> employeeList) {

            }

            @Override
            public void onFailure(String string) {

            }

            @Override
            public void onSuccessTimeRecord(StaffTimeRecordBean staffTimeRecordBean) {
                mView.successTimeRecord(staffTimeRecordBean);
            }

            @Override
            public void onCompleted() {
                mView.dismissWaiting();
            }

            @Override
            public void onFailure() {

            }

            @Override
            public void onSuccess() {

            }

            @Override
            public void noInternet() {

            }
        });
    }

    public void deleteTimeRecord(HashMap<String, String> map, CompositeDisposable compositeDisposable) {
        if (!isViewAttached()) {
            return;
        }
        mView = getView();
        mView.showWaiting();
        FetchListModel.toDeleteTimeRecord(map, compositeDisposable, new IFetchListModel() {
            @Override
            public void onSuccessEmployee(ArrayList<EmployeeBean> employeeList) {

            }

            @Override
            public void onSuccessProject(ArrayList<DetailProjectBean> projectList) {

            }

            @Override
            public void onSuccess(ArrayList<DetailProjectBean> projectList, ArrayList<EmployeeBean> employeeList) {

            }

            @Override
            public void onFailure(String string) {

            }

            @Override
            public void onSuccessTimeRecord(StaffTimeRecordBean staffTimeRecordBean) {
            }

            @Override
            public void onCompleted() {
                mView.dismissWaiting();
                mView.failureMessage("1");
            }

            @Override
            public void onFailure() {

            }

            @Override
            public void onSuccess() {

            }

            @Override
            public void noInternet() {

            }
        });
    }

}
